package com.fecean.aabbc.commons.easy.enums;

import com.fecean.aabbc.commons.enums.IEnum;

/**
 * 删除标志枚举
 * 
 * @author chenfenghai
 *
 */
public enum DelFlagEnum implements IEnum<Integer> {

    /**
     * 删除标志，0：未删除
     */
    NO(0, "未删除"),

    /**
     * 删除标志，1：已删除
     */
    YES(1, "已删除");

    private final Integer code;
    private final String text;

    DelFlagEnum(Integer code, String text) {
        this.code = code;
        this.text = text;
    }

    /**
     * 获取编码
     * 
     * @return
     */
    @Override
    public Integer getCode() {
        return code;
    }

    /**
     * 获取显示名称
     * 
     * @return
     */
    @Override
    public String getText() {
        return text;
    }

    /**
     * 根据编码获取对应的枚举，没有匹配则返回null
     * 
     * @param code
     * @return
     */
    public static DelFlagEnum getEnum(Object code) {
        if (code == null) {
            return null;
        }
        for (DelFlagEnum enumType : DelFlagEnum.values()) {
            if (enumType.compare(code)) {
                return enumType;
            }
        }
        return null;
    }

    /**
     * 比较，相同返回true，否则返回false
     * 
     * @param codeOrEnum
     *            编码或枚举
     * @return
     */
    public boolean compare(Object codeOrEnum) {
        if (code == null) {
            return false;
        }
        if (codeOrEnum instanceof DelFlagEnum) {
            return this.compareTo((DelFlagEnum)codeOrEnum) == 0;
        } else if (codeOrEnum instanceof Integer) {
            return this.code.compareTo((Integer)codeOrEnum) == 0;
        } else {
            return this.code.toString().equals(codeOrEnum);
        }
    }
}
